package sort;

import org.junit.Test;

public class BubbleSort {
	@Test
	public void fun() {
		int[] list = {1, 2, 3, 1, 4, 2};
		bubbleSort(list);
		for(int i : list) {
			System.out.print(i + "\t");
		}
	} 
	public void bubbleSort(int[] list) {
		int n = list.length - 1;
		for(int i = 0; i < n; i ++) {
			for(int j = 0; j < n - i; j ++) {
				if(list[j] > list[j + 1])
					swap(j, j + 1, list);
			}
		}
	}
	public void swap(int i, int j, int[]list) {
		int temp = list[i];
		list[i] = list[j];
		list[j] = temp;
	}
}
